import os.path

import matplotlib.pyplot as plt
from tensorboard.backend.event_processing import event_accumulator

def plt_figure(save_path, data):
    assert isinstance(data, list)

    if not len(data):
        return

    for i in range(0, len(data)):
            plt.scatter(i, data[i], color='blue', s=2)

    plt.xlabel('Epoch')
    plt.ylabel(save_path.split('\\')[-1].split('.')[0])

    plt.savefig(save_path)
    plt.close()

# 加载日志数据
ea = event_accumulator.EventAccumulator(r'D:\allworks\gbl\CLIP_linear_probe\clip_-linear_-probe\classify\res\tensorboard_data\L0.1_D0.5__lr0.002_wd0.02\events.out.tfevents.1718787290.DESKTOP-9BIMCAC.1572.0')
ea.Reload()

data = {}

for key in ea.scalars.Keys():
    val_psnr = ea.scalars.Items(key)
    data[key] = [i.value for i in val_psnr]

for key in data.keys():
    path_save = os.path.join(r'D:\allworks\gbl\CLIP_linear_probe\clip_-linear_-probe\classify\res\picture', f''.join([key.replace('/','_'), '_TB.jpg']))
    plt_figure(path_save, data[key])
